package com.iotteam.androidbase.moudules.main.presenter;

import android.text.TextUtils;

import com.iotteam.androidbase.R;
import com.iotteam.androidbase.base.BaseModel;
import com.iotteam.androidbase.commen.LocalInfoManager;
import com.iotteam.androidbase.commen.network.Api;
import com.iotteam.androidbase.commen.network.core.HttpListener;
import com.iotteam.androidbase.commen.network.core.HttpManager;
import com.iotteam.androidbase.commen.utils.ToastUtil;
import com.iotteam.androidbase.moudules.main.view.ISensorListView;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by lidechen on 6/4/17.
 */

public class SensorListCompl implements ISensorListPresenter {

    private ISensorListView mView;

    public SensorListCompl(ISensorListView view){
        mView = view;
    }

    @Override
    public void loadSensorList() {

        Map<String, String> param = new HashMap<>();
        param.put("mobile", LocalInfoManager.getInstance().getUserInfo().getMobile());
        HttpManager.getInstance().postBean(Api.getTerInfo, param, BaseModel.class, new HttpListener<BaseModel>() {
            @Override
            public void onSucceed(int what, BaseModel bean) {
                if(bean.getCode() == 0){

                }else{
                    if(!TextUtils.isEmpty(bean.getMessage())) {
                        ToastUtil.showShort(bean.getMessage());
                    }else{
                        ToastUtil.showShort(R.string.dialog_reuest_info_err);
                    }
                }
            }

            @Override
            public void onFailed(int what, Exception e) {

            }

            @Override
            public void onStart(int what) {
                mView.startRefreshView();
            }

            @Override
            public void onFinish(int what) {
                mView.endRefreshView();
            }
        });
    }
}
